kappa = 500;
gamma = kappa;
K_coe = 100;
num_train = 5001;
num_val = 2048;

num_test = 20001;
delta_list = [0];
 
syms s
% y = @(s) (3*s.^2+2*s+1).*sin(100*s)+(9*s.^2+5*s+8).*sin(100*s)*1j;
% fun = @ (s) y(s).*((3*s.^2+2*s+1).*sin(100*s)-(9*s.^2+5*s+8).*sin(100*s)*1j);

y = @(s) abs(s).^(0.1).*log(abs(s)).^1.*s./abs(s).*(sin(abs(s))+s.^3.*exp(100*1j*s)+cosh(s).*exp(300*1j*s)+s.^2.*exp(-350*1j*s)+sinh(s).*exp(400*1j*s)+(s.^3+sin(s)).*exp(450*1j*s)+abs(s).^3.*exp(-500*1j*s));

%fun = @(s) y(s).*(s.^1.*log(abs(s)).^1.*(sin(abs(s))+s.^3.*exp(-100*1j*s)+cosh(s).*exp(-300*1j*s)+s.^2.*exp(350*1j*s)+sinh(s).*exp(-400*1j*s)+(s.^3+sin(s)).*exp(-450*1j*s)+abs(s).^3.*exp(500*1j*s)));
fun = @(s) abs(y(s)).^2;
% y= @(s) sin(abs(s))+s.^3.*exp(250*1j*s)+cosh(s).*exp(300*1j*s)+s.^2.*exp(-350*1j*s)+sinh(s).*exp(400*1j*s)+(s.^3+sin(s)).*exp(450*1j*s)+abs(s).^3.*exp(-500*1j*s);
% 
% fun = @(s) y(s).*(sin(abs(s))+s.^3.*exp(-250*1j*s)+cosh(s).*exp(-300*1j*s)+s.^2.*exp(350*1j*s)+sinh(s).*exp(-400*1j*s)+(s.^3+sin(s)).*exp(-450*1j*s)+abs(s).^3.*exp(500*1j*s));
%y = @(s) s;
%fun = @(s) s.^2;
int_val = integral(fun, -1, 1);
norm_y = sqrt(int_val);

x_rand_lim = rand(num_val, 1)*2-1;
x_lim2 = linspace(-1, 1, num_test)';
x_lim = [linspace(-1, 1, num_train)'; x_rand_lim];

real_y = real(y(x_lim2));
if isnan(real_y((num_test+1)/2, 1))
    real_y((num_test+1)/2, 1) = 0;
end

img_y = imag(y(x_lim2));
if isnan(img_y((num_test+1)/2, 1))
    img_y((num_test+1)/2, 1) = 0;
end

value_f = zeros(length(x_lim), 1);
first_value_f = zeros(length(x_lim), 1);
for i=1:length(x_lim)
    value_f(i,1) = y(x_lim(i, 1))- K_coe * integral(@ (t) exp(1i*kappa*abs(t-x_lim(i,1))).*y(t), -1, 1);
    first_value_f(i,1) =  integral(@ (t) exp(1i*kappa*abs(t-x_lim(i,1))).*y(t), -1, 1);
end

i = (num_train+1)/2;
value_f(i,1) = - K_coe * integral(@ (t) exp(1i*kappa*abs(t-x_lim(i,1))).*y(t), -1, 1);



for index = 1:1:1
    delta = delta_list(index);
    real_f = real(value_f)+delta*randn(size(value_f));
    img_f = imag(value_f)+delta*randn(size(value_f));

    l1st_app
    l2st_app
    %l3st_app


    name = sprintf('./exp3_com_%.3f_singu_01.mat', delta);
    save(name,"x_lim2", "K_coe", "kappa", "x_lim", "real_y", "img_y", "real_f", "img_f", "num_train", "num_val", "num_test", "norm_y")

end



